/**
 * 轮播图模块
 */
import React, {Component} from 'react';
import {View, StyleSheet,  Text,Platform} from  'react-native';
import Banner from 'react-native-banner';

export default class MyBanner extends Component {
    constructor(props) {
        super(props);

        this.banners = [
            {
                title: '李白一生喝了50+吨酒，他到底喝了什么？',
                image: 'http://bmob-cdn-9229.b0.upaiyun.com/2017/05/12/ea31410b405b0f97804f72c1747d0373.jpg',
                url:'http://mp.weixin.qq.com/s/ScU1xWcIA-V55gyDllC3Zg'
            },
            {
                title: '在Call me体验吧千万别强撩年轻貌美的姑娘，结果料想不到……',
                image: 'http://bmob-cdn-9229.b0.upaiyun.com/2017/05/12/a72bee014087bc138096a827a56c1f3c.jpg',
                url:'http://mp.weixin.qq.com/s/Ky6aD9iFp4iA0fKSiKc5GQ'

            },
            {
                title: '日本魔性撩汉广告，让我一分钟识别相亲/联谊妹子的招数',
                image: 'http://bmob-cdn-9229.b0.upaiyun.com/2017/05/12/18eeb9124058e49580e5172010ce9135.png',
                url:'http://mp.weixin.qq.com/s/yuTHIRkdA0NwV8BQmj0WwQ'
            },
            {
                title: '保守国家喝的什么酒？ 没想到伊朗、朝鲜喝酒竟是这样……',
                image: 'http://bmob-cdn-9229.b0.upaiyun.com/2017/05/12/c0ec9a9f40abcaaa800af2a9c6f00119.jpg',
                url:'http://mp.weixin.qq.com/s/e0EXNt1YJPAx_pvV1SOZ6w'
            },
        ];

        this.iosMarginTop = Platform.OS == 'ios' ? {marginTop: 20} : {};

        this.state = {
            clickTitle: 'You can try clicking beauty',
            defaultIndex: 0,
        };
        this.defaultIndex = 0;
    }

    render() {
        return (
            <View style={[styles.container, this.iosMarginTop]}>
                <Banner
                    banners={this.banners}
                    defaultIndex={this.defaultIndex}
                    onMomentumScrollEnd={this.onMomentumScrollEnd.bind(this)}
                    intent={this.clickListener.bind(this)}
                />
            </View>
        );
    }

    clickListener(index) {
        if (this.props.popToHomeView == null) return;
        this.props.popToHomeView(this.banners[index].url,'文章');
    }

    onMomentumScrollEnd(event, state) {
        this.defaultIndex = state.index;
    }


}

MyBanner.propTypes = {
    popToHomeView: React.PropTypes.func
};
MyBanner.defaultProps = {
    popToHomeView: null
};
const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#F5FCFF',
    },
});